Public Sub SplitBatchByNumberOfDocuments(ByRef pXRootFolder As CASCADELib.CscXFolder,intSplitNumber As Integer) 'splits a batch into multiple batches based on a specified number of documents 'intSplitNumber - the number of documents in each new batch 'pXRootFolder - the root folder (batch level) object where document routing needs to be set 'counter for new batches created Dim intBatchCount As Integer 'flag to determine whether minimum documents for a new batch has been met Dim boolNewBatch As Boolean 'counter for documents marked as belonging to each new batch Dim intBatchDocsCount As Integer 'the xdocinfo for each document Dim xDocInfo As CscXDocLib.CscXDocInfo 'general counter Dim i As Integer 'set counters intBatchCount = 0 intBatchDocsCount = 0 boolNewBatch = False 'loop all documents in the batch For i = 0 To pXRootFolder.GetTotalDocumentCount - 1 'get the xdocinfo for this document Set xDocInfo = pXRootFolder.GetDocInfoByGlobalIndex(i) 'check if loop counter indicates ready to create new batches (met the minimum number to start creating new batches) If i = intSplitNumber Then boolNewBatch = True 'if new batch is required, start to count documents and create new batches If boolNewBatch = True Then 'increment the documents processed into new batches intBatchDocsCount=intBatchDocsCount+1 'if this is the first document for a new batch, create a new batch flag at the XRootFolder level - this creates the batch If intBatchDocsCount=1 Then 'increment new batches counter intBatchCount=intBatchCount+1 'create the new batch reference pXRootFolder.XValues.Set("KTM_DOCUMENTROUTING_BATCHNAME_" & "SPLITBATCH" & CStr(intBatchCount), pXRootFolder.XValues("AC_BATCH_NAME") & " " & CStr(intBatchCount)) End If 'mark this document as belonging to the latest new batch xDocInfo.XValues.Set("KTM_DOCUMENTROUTING", "SPLITBATCH" & CStr(intBatchCount)) 'reset document counter if reached the maximum for a batch If intBatchDocsCount=intSplitNumber Then intBatchDocsCount=0 End If End If Next End Sub